//
//  AppDelegate.m
//  Streaming
//
//  Created by 官琛 on 15-6-20.
//  Copyright (c) 2015年 liuxun. All rights reserved.
//

#import "AppDelegate.h"

@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    // Override point for customization after application launch.
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    [self.window makeKeyAndVisible];
    [self.window setBackgroundColor:[UIColor whiteColor]];
    
    
    MovieViewController *movieVC = [[MovieViewController alloc] init];
    UINavigationController *movieNav = [[UINavigationController alloc] initWithRootViewController:movieVC];
    UIImage *movieImage = [UIImage imageNamed:@"iconfont-dianying.png"];
    UIImage *movieselectedImage = [UIImage imageNamed:@"iconfont-dianying-2.png"];
    movieNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"电影" image:movieImage selectedImage:movieselectedImage];
    
    CemeraViewController *cemeraVC = [[CemeraViewController alloc] init];
    UINavigationController *cemeraNav = [[UINavigationController alloc] initWithRootViewController:cemeraVC];
    UIImage *cemeraImage = [UIImage imageNamed:@"iconfont-icon2.png"];
    UIImage *cemeraselectedImage = [UIImage imageNamed:@"iconfont-icon.png"];
    cemeraNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"排行榜" image:cemeraImage selectedImage:cemeraselectedImage];
    
    CommentViewController *newsVC = [[CommentViewController alloc] init];
    UINavigationController *newsNav = [[UINavigationController alloc] initWithRootViewController:newsVC];
    UIImage *newsImage = [UIImage imageNamed:@"iconfont-pinglun-3.png"];
    UIImage *newsselectedImage = [UIImage imageNamed:@"iconfont-pinglun-4.png"];
    newsNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"影评" image:newsImage selectedImage:newsselectedImage];
    
    RealViewController *shopVC = [[RealViewController alloc] init];
    UINavigationController *shopNav = [[UINavigationController alloc] initWithRootViewController:shopVC];
    UIImage *shopImage = [UIImage imageNamed:@"iconfont-redian.png"];
    UIImage *shopselectedImage = [UIImage imageNamed:@"iconfont-redian-2.png"];
    shopNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"热点" image:shopImage selectedImage:shopselectedImage];
    
    PrevueViewController *prevueVC = [[PrevueViewController alloc] init];
    UINavigationController *prevueNav = [[UINavigationController alloc] initWithRootViewController:prevueVC];
    UIImage *mainImage = [UIImage imageNamed:@"iconfont-huandengpian.png"];
    UIImage *mainselectedImage = [UIImage imageNamed:@"iconfont-huandengpian-2.png"];
    prevueNav.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"预告片" image:mainImage selectedImage:mainselectedImage];
    
    movieNav.navigationBar.barTintColor = [UIColor colorWithRed:31 / 255.0 green:115 / 255.0 blue:192 / 255.0 alpha:0.3f];
    cemeraNav.navigationBar.barTintColor = [UIColor colorWithRed:31 / 255.0 green:115 / 255.0 blue:192 / 255.0 alpha:0.5f];
    newsNav.navigationBar.barTintColor = [UIColor colorWithRed:31 / 255.0 green:115 / 255.0 blue:192 / 255.0 alpha:0.3f];
    shopNav.navigationBar.barTintColor = [UIColor colorWithRed:31 / 255.0 green:115 / 255.0 blue:192 / 255.0 alpha:0.3f];
    prevueNav.navigationBar.barTintColor = [UIColor colorWithRed:31 / 255.0 green:115 / 255.0 blue:192 / 255.0 alpha:0.3f];
    
    
    UITabBarController *tabBarC = [[UITabBarController alloc] init];
    tabBarC.viewControllers = [NSArray arrayWithObjects:movieNav, cemeraNav,newsNav, shopNav, prevueNav, nil];
    tabBarC.tabBar.translucent = NO;
//    [self.window setRootViewController:tabBarC];
    

    
    LeftViewController *leftMenuViewController = [[LeftViewController alloc] init];
    RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:tabBarC
    leftMenuViewController:leftMenuViewController
    rightMenuViewController:nil];
    sideMenuViewController.backgroundImage = [UIImage imageNamed:@"Stars"];
    sideMenuViewController.menuPreferredStatusBarStyle = 1; // UIStatusBarStyleLightContent
    sideMenuViewController.delegate = self;
    sideMenuViewController.contentViewShadowColor = [UIColor blackColor];
    sideMenuViewController.contentViewShadowOffset = CGSizeMake(0, 0);
    sideMenuViewController.contentViewShadowOpacity = 0.6;
    sideMenuViewController.contentViewShadowRadius = 12;
    sideMenuViewController.contentViewShadowEnabled = YES;
    self.window.rootViewController = sideMenuViewController;

    
#pragma 开机动画
    static BOOL number=0;
    NSUserDefaults *library=[NSUserDefaults standardUserDefaults];
    
    if ([library objectForKey:@"libraryNumber"]==nil){
        
        [library setBool:number forKey:@"libraryNumber"];
        
        NSArray *coverImageNames = @[@"1.png", @"2.png"];
        NSArray *backgroundImageNames = @[@"1.png", @"2.png"];
        NSLog(@"走没走");
        
        self.introductionView = [[ZWIntroductionViewController alloc]initWithCoverImageNames:coverImageNames backgroundImageNames:backgroundImageNames];
        [self.window addSubview:self.introductionView.view];
        
        __weak AppDelegate *weakSelf = self;
        self.introductionView.didSelectedEnter = ^() {
            [weakSelf.introductionView.view removeFromSuperview];
            weakSelf.introductionView = nil;
            
            
        };
        
    }
    
//    UIImageView *view1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.window.frame.size.width , self.window.frame.size.height)];
//    view1.backgroundColor = [UIColor orangeColor];
//    view1.image = [UIImage imageNamed:@"12346.jpg"];
//    [self.window addSubview:view1];
//    
//    
//    
//    [UIView animateWithDuration:2 delay:1 usingSpringWithDamping:1 initialSpringVelocity:0.5 options:UIViewAnimationOptionLayoutSubviews animations:^{
//        
//        view1.frame = CGRectMake(0, -self.window.frame.size.height, self.window.frame.size.width , self.window.frame.size.height);
//        
//    } completion:^(BOOL finished) {
//        
//        [view1 removeFromSuperview];
//        
//        
//    }];
    

    [NSThread sleepForTimeInterval:2.0];
    
    AFNetworkReachabilityManager *mgr = [AFNetworkReachabilityManager sharedManager];
    [mgr setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        
        UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(WIDTH, 60, 180, 30)];
        label1.textColor = [UIColor redColor];
        [self.window addSubview:label1];
        
        switch (status) {
            case AFNetworkReachabilityStatusUnknown:
            case AFNetworkReachabilityStatusNotReachable:
                NSLog(@"当前无网络");
                label1.text = @"当前无网络部分页面无法正常显示";
                [UIView animateWithDuration:3 animations:^{
                    
                    
                    label1.frame = CGRectMake(WIDTH-label1.frame.size.width-380, 60, 240, label1.frame.size.height);
                    
                }];
                
                [UIView animateWithDuration:5 animations:^{
                    
                    
                    label1.frame = CGRectMake(WIDTH, 60, 260, label1.frame.size.height);
                    
                }];
                
                //                MBProgressHUD showHUDAddedTo:<#(UIView *)#> animated:<#(BOOL)#>
                break;
            case AFNetworkReachabilityStatusReachableViaWWAN:
                NSLog(@"手机自带网络");
                
                label1.text = @"当前是手机自带网络请注意流量";
                
                
                [UIView animateWithDuration:3 animations:^{
                    
                    label1.frame = CGRectMake(WIDTH-label1.frame.size.width-360, 60, 240, label1.frame.size.height);
                    
                }];
                
                [UIView animateWithDuration:5 animations:^{
                    
                    
                    label1.frame = CGRectMake(WIDTH, 60, 250, label1.frame.size.height);
                    
                }];
                
                
                
            default:
            case AFNetworkReachabilityStatusReachableViaWiFi:
                NSLog(@"WIFI");
                
                label1.text = @"当前是WIFI网络";
                
                
                [UIView animateWithDuration:3 animations:^{
                    
                    
                    label1.frame = CGRectMake(WIDTH-label1.frame.size.width, 60, label1.frame.size.width, label1.frame.size.height);
                    
                }];
                
                [UIView animateWithDuration:7 animations:^{
                    
                    
                    label1.frame = CGRectMake(WIDTH, 60, label1.frame.size.width, label1.frame.size.height);
                    
                }];
                
                
                break;
        }
        [label1 autorelease];
    }];
    
    
    [mgr startMonitoring];
    

    
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    [[SDImageCache sharedImageCache]clearMemory];
    [[SDWebImageManager sharedManager]cancelAll];
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
